#!/usr/bin/env python
# coding=utf-8
from toughadmin.tools import pyforms
from toughadmin.tools.pyforms import dataform
from toughadmin.tools.pyforms import rules
from toughadmin.tools.pyforms.rules import button_style, input_style

boolean = {0: u"未激活", 1: u"激活"}

def policy_add_form():
    return pyforms.Form(
        pyforms.Textbox("policy_server_ip", rules.is_ip, description=u"策略服务器IP地址",required="required", **input_style),
        pyforms.Textbox("policy_auth_port", rules.is_number, description=u"策略服务器认证端口",required="required", **input_style),
        pyforms.Textbox("policy_acct_port", rules.is_number, description=u"策略服务器记账端口",required="required", **input_style),
        pyforms.Textbox("secret", rules.is_alphanum2(4, 32), description=u"共享秘钥", required="required",**input_style),
        pyforms.Dropdown("status", args=boolean.items(),description=u"状态,是否设置为活动服务器", required="required",help=u'此项值选中会立即生效',**input_style),
        pyforms.Button("submit", type="submit", html=u"<b>提交</b>", **button_style),
        title=u"增加策略服务器信息",
        action="/policy/add",
    )

def policy_update_form():
    return pyforms.Form(
        pyforms.Hidden("id", description=u"编号"),
        pyforms.Textbox("policy_server_ip", rules.is_ip, description=u"策略服务器IP地址",required="required", **input_style),
        pyforms.Textbox("policy_auth_port", rules.is_number, description=u"策略服务器认证端口", required="required",**input_style),
        pyforms.Textbox("policy_acct_port", rules.is_number, description=u"策略服务器记账端口", required="required",**input_style),
        pyforms.Textbox("secret", rules.is_alphanum2(4, 32), description=u"共享秘钥", required="required", **input_style),
        pyforms.Button("submit", type="submit", html=u"<b>提交</b>", **button_style),
        title=u"修改策略服务器信息",
        action="/policy/update",
    )